package com.lx.patterns.proxy.jdk_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName ProxyFactory
 * @Description: //todo
 * @Author: 落雪
 * @CreateDate: 2025/1/16 21:07
 * @UpdateUser: 落雪
 * @UpdateDate: 2025/1/16 21:07
 * @UpdateRemark:
 * @Version: 1.0
 */
public class ProxyFactory {

    private TrainStation station = new TrainStation();

    public SellTickets getProxyObject(){


        return (SellTickets)Proxy.newProxyInstance(station.getClass().getClassLoader(), station.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("代理点收取一些服务费用(jdk动态代理)");
                return method.invoke(station,args);
            }
        });
    }
}
